package com.shop.dao.impl;

import com.shop.dao.TOrderDao;
import com.shop.entity.Goods;
import com.shop.entity.ShowPageT;
import com.shop.entity.TOrder;
import com.shop.tools.JdbcTool;

import java.sql.SQLException;
import java.util.List;

/**
 * com.shop.dao.impl文档说明
 *
 * @author Angluzha
 * @version 2022/9/22
 */
public class TOrderDaoImpl implements TOrderDao {

    @Override
    public TOrder selectOne(TOrder tOrder) throws SQLException {
        String sql ="select * from t_order where id = ?";
        return JdbcTool.selectOne(TOrder.class,sql,tOrder.getId());
    }

    @Override
    public boolean update(TOrder tOrder) {
        return false;
    }

    @Override
    public boolean insert(TOrder t) {
        String sql ="insert into t_order(sid,uid,quantity,speed,gname,des,pnguri) values(?,?,?,?,?,?,?)";
        return JdbcTool.write(sql,t.getSid(),t.getUid(),t.getQuantity(),t.getSpeed(),t.getGname(),t.getDes(),t.getPnguri())>0;
    }

    @Override
    public boolean deleteById(Integer id) {
        String sql ="delete from t_order where id=?";
        return JdbcTool.write(sql,id)>0;
    }

    @Override
    public List<TOrder> selectAll() throws SQLException {
        return null;
    }

    @Override
    public ShowPageT<TOrder> selectPage(ShowPageT<TOrder> page) throws SQLException {
        String sql = "SELECT t_order.*, s_user.username, s_order.date,s_order.statu FROM t_order INNER JOIN s_order ON t_order.sid = s_order.id INNER JOIN s_user ON s_order.`user` = s_user.id LIMIT ?,?";
        String sql2 = "select count(1) from t_order";
        page.setCount(JdbcTool.selectResult(Integer.class,sql2));
        page.setData(JdbcTool.selectList(TOrder.class,sql,page.getSize()*(page.getPage()-1),page.getSize()));
        return page;
    }

    @Override
    public int delCheck(List<Integer> list) {
        return 0;
    }
}
